package com.example.bishe.web.c.controller;

import com.example.bishe.entity.User;
import com.example.bishe.service.UserService;
import com.example.bishe.util.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能描述
 *
 * @author: LDH
 * @date: 2023年04月16日 12:52
 */
@RestController
@Api(value = "客户端查询", tags = {"查询用户数据"})
@RequestMapping("/c/user")
public class CUserController {

    @Autowired
    private UserService userService;

    @ApiOperation("用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openid", value = "用户openid", paramType = "query")
    })
    @PostMapping("/login")
    public RestResult<User> login(@RequestBody String openId){
        return RestResult.get_success(userService.login(openId));
    }

    @ApiOperation("用户授权头像/昵称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query"),
            @ApiImplicitParam(name = "avatarUrl", value = "用户头像", paramType = "query"),
            @ApiImplicitParam(name = "nickName", value = "用户微信昵称", paramType = "query")
    })
    @PostMapping("/auth")
    public RestResult<User> auth(
            @RequestParam Long userId,
            @RequestParam String avatarUrl,
            @RequestParam String nickName
    ){
        return RestResult.get_success(userService.updateByAuth(userId,avatarUrl,nickName));
    }

}